puts "hello"
require './reg.rb'
require './http.rb'
require './const.rb'
require 'net/http'
require 'uri'
require 'json'
require 'write_xlsx'
require './library.rb'
############################### describe ###################################
# author：SummerStarBreeze
# 本文件为ruby的启动脚本
# 用于 读取商户信息以及附件 去 调用接口上传，以及收集错误信息
# 安装相应的依赖：gem i bundle , bundle i
# 执行命令：ruby auto.rb
############ function and const area ####################
# 所有对应的方法都通过rb文件导入
# const.rb、http.rb 、library.rb
###################### 变量状态 #########################
count = 0             # 计数，用于累计商户执行数量
col = 0               # excel列位移，用于插入出现错误信息时在excel表格里插入错误信息 
merchant_msg = ""         # 商户信息
franchisee_id = ""        # 加盟店编号
merchant_id = ""          # 商户编号
Media_types = ['application/json','application/x-www-form-urlencoded','multipart/form-data','text/plain']
Dir.foreach(Directory) do |entry|
  next if entry == '.' || entry == '..' # 忽略当前目录和上级目录
  path = File.join(Directory, entry) # 获取条目的完整路径
  count = count + 1
  franchisee_id = match_m_number(entry)
  if Dir.exist?(path) # 检查条目是否为目录
    # 进入子目录对txt文件进行的内容进行读取
    puts "#{count}.加盟店编号: #{franchisee_id} "
    if File.file?(path+'/新建文本文档.txt')
        file = File.read(path+'/新建文本文档.txt')
        puts file
    end
    # 创建商户
    {
      "business" => {
          "short_name" => "唐猪猪"
      },
      "license_type" => "3",
      "owner" => {
          "idcard_type"=> 1,
          "mobile" => "17674198620",
          "name" => "唐猪猪",
          "idcard_num" => "431021200102038814",
          "idcard_back_img" => "0f169050-b0f0-11ed-9c17-1fdf1e1f77f5.jpg",
          "idcard_front_img" => "0f169050-b0f0-11ed-9c17-1fdf1e1f77f5.jpg"
      },
      "parent_id" => "3098969723303254",
      "snb_info" => {
          "notify_url" => "https://md.pooul.com/v2_test/notify",  
          "redirect_path" => "https://mm.pooulcloud.cn/v2/#/login.."
      }
    }
    # 进件：获取七牛token，上传身份证，绑定银行卡
    # puts "#{count}.加盟店编号: #{franchisee_id} "
    # merchant_msg = request_fun({ "regex" => franchisee_id, "status" => 5, "business_type" => false },'POST',Url,Token)
    
    # if merchant_msg != []
    #   merchant_id = merchant_msg[0]["merchant_id"]
    #   puts "开户链接：" + "https://m.pooul.com/mobile/snb_open_one?merchant_id=" + merchant_id
    #   puts "商户编号：" + merchant_id
    #   zt_signs_token = request_fun("https://api.pooul.com/web/public/zt_signs/#{merchant_id}/snb_single_token","")
    #   if zt_signs_token["code"] == 7              # 状态码 为 7 则代表找不到该商户编号
    #     excel_write(col,0,franchisee_id)
    #     excel_write(col,0,merchant_id)
    #     excel_write(col,2,zt_signs_token["msg"])
    #     col = col + 1
    #   elsif zt_signs_token["code"] == 116            # 状态码 为 116 则代表已上传
    #     excel_write(col,0,franchisee_id)
    #     excel_write(col,0,merchant_id)
    #     excel_write(col,2,zt_signs_token["msg"])
    #     col = col + 1
    #   else
    #     puts "token of seven beef:" 
    #     puts zt_signs_token["data"]["token"]
    #   end
    # else 
    #   puts merchant_msg 
    # end
    # puts JSON.parse(zt_signs_token)["code"]
    
    # 如果存在七牛的token则上传附件
#     if zt_signs_token != [] && zt_signs_token.key?("data")
#       # 
#       request_fun({ "x:extend_param" => {"legalPersonIdNo":"
# 8002342703120628","legalPersonName":"孙悟空"}, 
#         "x:file_type" => "1101_Z101", 
#         "key" => "c7c978c0-b0cc-11ed-856a-bd695ffbecaz.jpg",
#         "x:pm_id" => ,
#         "token" => Token,
#          },'UPLOAD',"http://qiniu.pooulcloud.cn/key",Token)
#     end
    puts "---------------------------------------" 
    sleep(1)
  end
end


# 将没有信息

